package com.dudsbury.gui;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.joda.time.DateTime;

import com.dudsbury.database.MyDateTime;
import com.dudsbury.jtablestuff.CustomTable;
import com.toedter.calendar.JCalendar;

public class CalendarFrame extends JFrame implements ActionListener {

	CustomTable table;
	JCalendar calendar;
	JButton button;

	public CalendarFrame(CustomTable table) {
		setTitle("Calender");
		JPanel panel = new JPanel();
		setSize(250, 250);
		setResizable(false);
		setLocationRelativeTo(null);
		this.table = table;
		calendar = new JCalendar();
		panel.add(calendar);
		button = new JButton("Select Date");
		button.addActionListener(this);

		panel.add(button);
		getContentPane().add(panel);
		setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		DateTime datehold = new DateTime(calendar.getDate());
		table.setCurrentDate(new MyDateTime(datehold));
		if (table.getCurrentView() == table.WEEKLY_VIEW) {

			table.setWeeklyView();

		} else {

			table.setMonthlyView();
		}
		this.dispose();
		

	}

}
